﻿<%@ Page Title="" Language="C#" MasterPageFile="~/DefaultSite.Master" AutoEventWireup="true"
    CodeBehind="VoluntaryActivitySearch.aspx.cs" Inherits="SocialIn.Web.Search.VoluntaryActivitySearch" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="Search">
        <div class="HelpEventTitle"></div>
        <input id="hfCurrentPage" type="hidden" runat="server" />
        <input id="htTotalPage" type="hidden" runat="server" />
        <asp:DropDownList ID="ddlLocation" runat="server" Width="100">
        </asp:DropDownList>
        <asp:DropDownList ID="ddlTalent" runat="server" Width="100">
        </asp:DropDownList>
        <input id="tbSearch" type="text" class="SearchTextBox" runat="server" />
        <img id="imgLoading" alt="검색" src="/res/img/search/Search_SearchBtn.png" onclick="search();" class="SearchButton" />
        <div style="height:40px;"></div>
        <div class="Description">* 재능을 나누어 줄 수 있는 곳의 리스트입니다.</div>
        <div id="boardItemList" runat="server" enableviewstate="false"></div>
        <div class="PagerContainer">
            <div id="boardPagerCtl" class="pager"></div>
        </div>
        <uc:UCVolunteer ID="searchVolunteer" runat="server" />
    </div>
    <script type="text/javascript">
        function onFailed(error, userContext, methodName) {
            endLoading();

            alert(error.get_message());
        }

        function viewDialog(title, message) {
            $("#infoDialog").attr("title", title);
            $("#infoDialogMessage").html(message);

            $('#infoDialog').dialog('open');
        }

        $(document).ready(function () {
            var totalItemCount = parseInt($("#<%=htTotalPage.ClientID %>").attr("value"));
            $("#boardPagerCtl").pager({ pagenumber: 1, pagecount: totalItemCount, buttonClickCallback: pageClick });
            $("#<%=hfCurrentPage.ClientID %>").attr("value", 1);
        });

        pageClick = function (pageclickednumber) {
            var totalItemCount = parseInt($("#<%=htTotalPage.ClientID %>").attr("value"));
            var curPage = $("#<%=hfCurrentPage.ClientID %>");
            var bId = curPage.attr("item");

            $("#boardPagerCtl").pager({ pagenumber: pageclickednumber, pagecount: totalItemCount, buttonClickCallback: pageClick });
            curPage.attr("value", pageclickednumber);

            var location = $('#<%=ddlLocation.ClientID %>').val();
            var talent = $('#<%=ddlTalent.ClientID %>').val();
            var title = $('#<%=tbSearch.ClientID %>').attr('value');

            if (location == "-1") {
                location = null;
            }

            if (talent == "-1") {
                talent = null;
            }

            showLoading();

            itemReadServerCall(location, talent, pageclickednumber, title);
        }

        function itemReadServerCall(location, talent, pageNumber, title) {
            PageMethods.ItemRead(pageNumber, location, talent, title, onItemReadSucceeded, onFailed);
        }

        function onItemReadSucceeded(result, userContext, methodName) {
            endLoading();

            document.getElementById("<%=boardItemList.ClientID %>").innerHTML = result;
            document.body.style.cursor = "default";
        }

        function search() {
            var location = $('#<%=ddlLocation.ClientID %>').val();
            var talent = $('#<%=ddlTalent.ClientID %>').val();
            var title = $('#<%=tbSearch.ClientID %>').attr('value');

            if (location == "-1") {
                location = null;
            }

            if (talent == "-1") {
                talent = null;
            }

            showLoading();

            PageMethods.TotalItemCount(location, talent, title, function (result) {
                $("#<%=htTotalPage.ClientID %>").attr("value", result);
                $("#<%=hfCurrentPage.ClientID %>").attr("value", 1);

                var totalItemCount = parseInt(result);
                $("#boardPagerCtl").pager({ pagenumber: 1, pagecount: totalItemCount, buttonClickCallback: pageClick });

                itemReadServerCall(location, talent, 1, title);
            }
            , onFailed);
        }
    </script>
</asp:Content>
